Skip to content

fix: handle null only for outer list#1250

Merged
Noroth merged 3 commits intomasterfrom
ludwig/improve-nullability
Jul 28, 2025
Merged

fix: handle null only for outer list#1250
Noroth merged 3 commits intomasterfrom
ludwig/improve-nullability

Conversation

@Noroth
Copy link
Copy Markdown
Contributor

@Noroth Noroth commented Jul 28, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of empty and null items in nested lists within gRPC responses, ensuring stricter error reporting and correct output for non-nullable and nullable fields.
  • Tests

    • Added a test to verify correct handling of empty and nullable list items in GraphQL responses.
    • Enhanced mock data to include cases with empty lists and null entries for more comprehensive testing.

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.

@Noroth Noroth requested review from a team, StarpTech, devsergiy and jensneuse as code owners July 28, 2025 14:31
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 28, 2025

Walkthrough

A new subtest was added to the gRPC subgraph execution test suite to validate handling of empty and nullable list items. The mock gRPC service was updated to return empty and null user group lists. The gRPC datasource logic was modified to adjust error handling and output for invalid nested messages and lists during list flattening.

Changes

Cohort / File(s) Change Summary
Test Addition: Subgraph Execution
execution/engine/execution_engine_grpc_test.go
Added a subtest to TestGRPCSubgraphExecution that runs a query with nested lists containing empty and null items, asserting correct handling and response structure.
Mock Data Update: gRPC Test Service
v2/pkg/grpctest/mockservice.go
Modified the mock service to append an empty list and a null value to the AuthorGroups field in the QueryAuthor response, enabling testing of empty and nullable nested lists.
List Flattening & Error Handling Logic
v2/pkg/engine/datasource/grpc_datasource/grpc_datasource.go
Updated the traverseList function to: (1) return an error for invalid nested messages in non-nullable lists, (2) always return an empty array for invalid nested lists, and (3) clarify nullability handling in comments. No changes to exported function signatures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ecdd9d7 and 5603361.

📒 Files selected for processing (3)
  • execution/engine/execution_engine_grpc_test.go (1 hunks)
  • v2/pkg/engine/datasource/grpc_datasource/grpc_datasource.go (2 hunks)
  • v2/pkg/grpctest/mockservice.go (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: Noroth
PR: wundergraph/graphql-go-tools#1246
File: v2/pkg/engine/datasource/grpc_datasource/execution_plan_visitor.go:457-457
Timestamp: 2025-07-28T12:44:56.405Z
Learning: In the graphql-go-tools gRPC datasource, only non-null lists use protobuf's repeated field syntax directly. For nullable or nested lists, wrapper types are used because protobuf repeated fields cannot be nullable. The TypeIsNonNullList check ensures only appropriate list types are marked as repeated in the protobuf message structure.
Learnt from: SkArchon
PR: wundergraph/graphql-go-tools#1203
File: v2/pkg/engine/resolve/loader.go:63-67
Timestamp: 2025-07-02T15:28:02.122Z
Learning: In the graphql-go-tools codebase, result structs are consistently initialized with non-nil bytes.Buffer instances, making additional nil checks for res.out unnecessary defensive programming.
v2/pkg/engine/datasource/grpc_datasource/grpc_datasource.go (1)

Learnt from: Noroth
PR: #1246
File: v2/pkg/engine/datasource/grpc_datasource/execution_plan_visitor.go:457-457
Timestamp: 2025-07-28T12:44:56.405Z
Learning: In the graphql-go-tools gRPC datasource, only non-null lists use protobuf's repeated field syntax directly. For nullable or nested lists, wrapper types are used because protobuf repeated fields cannot be nullable. The TypeIsNonNullList check ensures only appropriate list types are marked as repeated in the protobuf message structure.

execution/engine/execution_engine_grpc_test.go (2)

Learnt from: Noroth
PR: #1246
File: v2/pkg/engine/datasource/grpc_datasource/execution_plan_visitor.go:457-457
Timestamp: 2025-07-28T12:44:56.405Z
Learning: In the graphql-go-tools gRPC datasource, only non-null lists use protobuf's repeated field syntax directly. For nullable or nested lists, wrapper types are used because protobuf repeated fields cannot be nullable. The TypeIsNonNullList check ensures only appropriate list types are marked as repeated in the protobuf message structure.

Learnt from: SkArchon
PR: #1203
File: v2/pkg/engine/resolve/loader.go:63-67
Timestamp: 2025-07-02T15:28:02.122Z
Learning: In the graphql-go-tools codebase, result structs are consistently initialized with non-nil bytes.Buffer instances, making additional nil checks for res.out unnecessary defensive programming.

🧬 Code Graph Analysis (3)
v2/pkg/engine/datasource/grpc_datasource/grpc_datasource.go (2)
v2/pkg/engine/datasource/grpc_datasource/execution_plan.go (1)
  • LevelInfo (189-192)
v2/pkg/graphqljsonschema/jsonschema.go (1)
  • NewNull (426-430)
execution/engine/execution_engine_grpc_test.go (1)
v2/pkg/grpctest/mapping/mapping.go (1)
  • DefaultGRPCMapping (10-954)
v2/pkg/grpctest/mockservice.go (1)
v2/pkg/grpctest/productv1/product.pb.go (3)
  • ListOfUser_List (7603-7608)
  • ListOfUser_List (7621-7621)
  • ListOfUser_List (7636-7638)
🔇 Additional comments (4)
v2/pkg/grpctest/mockservice.go (1)

1631-1634: LGTM! Well-structured test data for edge case validation.

These additions effectively test two important edge cases for nested list handling:

  1. Empty list: Uses proper wrapper structure {List: &productv1.ListOfUser_List{}} rather than nil
  2. Null item: Tests null handling at the outer list level, which aligns with the PR objective "handle null only for outer list"

The clear comments and proper protobuf structure make this excellent test data for validating the gRPC datasource's handling of empty and nullable nested lists.

execution/engine/execution_engine_grpc_test.go (1)

1436-1453: LGTM! Well-structured test for empty and nullable list handling.

This test effectively validates the handling of empty and nullable list items in gRPC subgraph execution. The test structure follows established patterns and the expected response correctly demonstrates nested list handling with both empty arrays ([]) and null values (null) within the authorGroups field.

v2/pkg/engine/datasource/grpc_datasource/grpc_datasource.go (2)

332-334: Approve the simplified list handling logic.

The change to always return an empty array for invalid lists is well-justified by the updated comment. Since nullability checking is handled at the outer list wrapper level, this simplification makes the code more predictable and easier to understand.

The comment clearly explains the rationale: "nullability is checked on the outer List wrapper type," which aligns with the retrieved learning about protobuf repeated fields not being nullable directly.


302-307: Review nested invalid wrapper handling for non-nullable lists

In traverseList (grpc_datasource.go lines ~303–307), when a nested wrapper message is invalid for a non-nullable list you now return an empty array (arena.NewArray()) plus an error. All other error branches in this function return arena.NewNull(), with or without an error. This is the only occurrence of NewArray(), fmt.Errorf(...).

Please confirm whether this deviation is intentional. If it is, consider adding a clarifying comment; otherwise you may want to return NewNull() for consistency or adjust the logic to match the intended JSON shape.

• File: v2/pkg/engine/datasource/grpc_datasource/grpc_datasource.go
Lines 303–307:

if !msg.IsValid() {
    if md.LevelInfo[level].Optional {
        return arena.NewNull(), nil
    }

    // Inconsistent with other error cases that return NewNull()
    return arena.NewArray(), fmt.Errorf("cannot add null item to response for non nullable list")
}
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ludwig/improve-nullability

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Noroth
Copy link
Copy Markdown
Contributor Author

Noroth commented Jul 28, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 28, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Noroth
Copy link
Copy Markdown
Contributor Author

Noroth commented Jul 28, 2025

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 28, 2025

✅ Actions performed

Full review triggered.

@Noroth Noroth merged commit 0e055a4 into master Jul 28, 2025
12 of 15 checks passed
@Noroth Noroth deleted the ludwig/improve-nullability branch July 28, 2025 15:11
Noroth pushed a commit that referenced this pull request Jul 28, 2025
🤖 I have created a release *beep* *boop*
---


##
[2.0.0-rc.212](v2.0.0-rc.211...v2.0.0-rc.212)
(2025-07-28)


### Bug Fixes

* handle null only for outer list
([#1250](#1250))
([0e055a4](0e055a4))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved handling of null values to ensure they are only applied to
the outer list.

* **Documentation**
* Added a new changelog entry for version 2.0.0-rc.212, detailing the
latest bug fix.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants